package com.orangecy.rulesubscribe.actuator;

import com.orangecy.common.exception.OrangeCyException;
import com.orangecy.common.util.SpringContextHolder;
import com.orangecy.rulesubscribe.component.RuleComponentService;
import com.orangecy.rulesubscribe.context.RuleContext;
import com.orangecy.rulesubscribe.define.RuleActuatorDTO;
import com.orangecy.rulesubscribe.define.RuleDefineDTO;
import com.orangecy.rulesubscribe.enums.ActuatorTypeEnum;

/**
 * @Author : orangeCy.奕
 * @Product : 猎豹养成产品源码
 * @Time : 2021/11/14
 * @Desc :
 */
public class BeanActuatorStrategy implements ActuatorStrategy {
    @Override
    public RuleActuatorDTO actuator(RuleContext context, RuleDefineDTO ruleDefineDTO) {
        RuleComponentService ruleComponentService;
        try {
            ruleComponentService = SpringContextHolder.getBean(ruleDefineDTO.getActuatorProcessor(), RuleComponentService.class);
        }catch (Exception rx){
            throw new OrangeCyException("rule component setting error");
        }
        return ruleComponentService.execute(context,ruleDefineDTO);
    }

    @Override
    public String getActuatorType() {
        return String.valueOf(ActuatorTypeEnum.BEAN_PROCESSOR.getType());
    }
}